package com.chen.dao;

import com.chen.model.Imports;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface ImportsDao {

    @Insert("insert into imports values (#{import_id},#{goods.goods_id},#{import_number},#{import_state},#{import_time})")
    int addImport(Imports imports);

    @Select("select * from imports")
    @Results({
            @Result(id = true, column="import_id",property = "import_id" ),
            @Result(column="import_number",property = "import_number" ),
            @Result(column="import_state",property = "import_state" ),
            @Result(column="import_time",property = "import_time" ),
            @Result(column="goods_id",property="goods",
                    one=@One(select="com.chen.dao.GoodsDao.findGoodsById",fetchType= FetchType.EAGER)),
    })
    List<Imports> findAllImports();

    @Update("update imports set import_state=#{import_state} where import_id=#{import_id}")
    int updateImports(Imports imports);

    @Select("select * from imports where import_id=#{import_id}")
    Imports findImportsById(Integer import_id);
}
